﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NAntExt.Aws
{
    /// <summary>
    /// The S3 path helpers and logic.
    /// </summary>
    public static class S3Path
    {
        /// <summary>
        /// Combines two S3 paths together.
        /// </summary>
        /// <param name="left">The left path.</param>
        /// <param name="right">The right path.</param>
        /// <returns>Returns the combined S3 path.</returns>
        public static string Combine(string left, string right)
        {
            return string.Format("{0}/{1}", left.TrimEnd('/'), right.TrimStart('/')).TrimStart('/');
        }

        /// <summary>
        /// Converts a file system path to an S3 path. Replaces all backslashes with forward slashes.
        /// </summary>
        /// <param name="fileSystemPath">The file system path.</param>
        /// <returns>Returns the S3 path representation of the file system path.</returns>
        public static string FromFileSystemPath(string fileSystemPath)
        {
            return fileSystemPath.Replace('\\', '/').TrimStart('/');
        }

        /// <summary>
        /// Converts S3 path to a file system path. Replaces all forward slashes to back slashes.
        /// </summary>
        /// <param name="fileSystemPath">The S3 path.</param>
        /// <returns>Returns the file system path from the S3 path.</returns>
        public static string ToFileSystemPath(string s3Path)
        {
            return s3Path.Replace('/', '\\');
        }
    }
}
